<?php

namespace app\admin\controller;

use app\common\logic\WalletLogic;
use PHPExcel;
class Profit extends Common
{

    public function __construct()
    {
        parent::__construct();
    }

    //申请运营中心
    public function operate()
    {
        if (input('get.keywords')) {
            $us_id = model("User")->where('us_nickname|us_tel', input('get.keywords'))->value('id');
            if (!$us_id) {
                $us_id = 0;
            }
            $this->map[] = ['us_id', '=', $us_id];
        }
        if (input('get.start') && input('get.end') == "") {
            $this->map[] = ['tx_add_time', '>=', input('get.start')];
        }
        if (input('get.start') == "" && input('get.end')) {
            $this->map[] = ['tx_add_time', '=<', input('get.end')];
        }
        if (input('get.start') && input('get.end')) {
            $this->map[] = ['tx_add_time', 'between', array(input('get.start'), input('get.end'))];
        }
        if (input('get.wa_type') != "") {
            $this->map[] = ['wa_type', '=', input('get.wa_type')];
        }

        //$field = 'a.*,b.us_nickname';
        $list = model('Tixian')->selects($this->map, $this->order, $this->size);
        foreach ($list as $k => $v) {
            $list[$k]['tx_account'] = model('User')->where('id', $v['us_id'])->value('us_tel');
        }
//        halt($list);
        $this->assign(array(
            'list' => $list,
        ));
        return $this->fetch();

    }


    //财富记录
    public function index()
    {
        if (is_post()) {

            $rst = model('Wallet')->xiugai([input('post.key') => input('post.value')], ['id' => input('post.id')]);
            return $rst;
        }
        if (input('get.keywords')) {
            $us_id = model("User")->where('us_account|us_real_name|us_tel', input('get.keywords'))->value('id');
            if (!$us_id) {
                $us_id = 0;
            }
            $this->map[] = ['us_id', '=', $us_id];
        }
        if (input('get.wa_type') != "") {
            $this->map[] = ['wa_type', '=', input('get.wa_type')];
        }
        $list = model('Wallet')->chaxun($this->map, $this->order, $this->size);
        $this->assign(array(
            'list' => $list,
        ));
        return $this->fetch();
    }

    // 提现记录
    public function commission()
    {
        if (input('get.keywords')) {
            $us_id = model("User")->where('us_nickname|us_tel', input('get.keywords'))->value('id');
            if (!$us_id) {
                $us_id = 0;
            }
            $this->map[] = ['us_id', '=', $us_id];
        }
        if (input('get.tixian_type')) {
            $this->map[] = ['tx_status', '=', input('get.tixian_type')];
        }
        if (input('get.start') && input('get.end') == "") {
            $this->map[] = ['tx_add_time', '>=', input('get.start')];
        }
        if (input('get.start') == "" && input('get.end')) {
            $this->map[] = ['tx_add_time', '=<', input('get.end')];
        }
        if (input('get.start') && input('get.end')) {
            $this->map[] = ['tx_add_time', 'between', array(input('get.start'), input('get.end'))];
        }
        if (input('get.wa_type') != "") {
            $this->map[] = ['wa_type', '=', input('get.wa_type')];
        }
        $this->map[] = ['tx_status', 'gt', 0];
        //$field = 'a.*,b.us_nickname';
        $list = model('Tixian')->chaxun($this->map, $this->order, $this->size);

        foreach ($list as $k => $v) {
            $list[$k]['bank_name'] = model('User')->where('id', $v['us_id'])->value('bank_name');
            if ($v['tx_type'] == 1) {
                $account = 'we_account';
                $list[$k]['tx_account'] = model('User')->where('id', $v['us_id'])->value($account);
            } elseif ($v['tx_type'] == 2) {
                $account = 'ali_account';
                $list[$k]['tx_account'] = model('User')->where('id', $v['us_id'])->value($account);
            }
        }

        $money = \model('tixian')

            ->where('tx_zhongxing','=',null)
            ->where('tx_status',1)
            ->where($this->map)
             ->sum('tx_num');
        $this->assign(array(
            'list' => $list,
            'money'=>$money
        ));
        return $this->fetch();
    }

//    //提现记录
//    public function commissionrecord()
//    {
//        if (input('get.keywords')) {
//            $us_id = model("User")->where('us_nickname|us_tel', input('get.keywords'))->value('id');
//            if (!$us_id) {
//                $us_id = 0;
//            }
//            $this->map[] = ['us_id', '=', $us_id];
//        }
//        if (input('get.start') && input('get.end') == "") {
//            $this->map[] = ['tx_add_time', '>=', input('get.start')];
//        }
//        if (input('get.start') == "" && input('get.end')) {
//            $this->map[] = ['tx_add_time', '=<', input('get.end')];
//        }
//        if (input('get.start') && input('get.end')) {
//            $this->map[] = ['tx_add_time', 'between', array(input('get.start'), input('get.end'))];
//        }
//        if (input('get.wa_type') != "") {
//            $this->map[] = ['wa_type', '=', input('get.wa_type')];
//        }
//        //halt($this->map);
//        $this->map[] = ['tx_status', 'eq', 1];
//        //$field = 'a.*,b.us_nickname';
//        $list = model('Tixian')->chaxun($this->map, $this->order, $this->size);
//        // halt($list);
//        foreach ($list as $k => $v) {
//            $list[$k]['bank_name'] = model('User')->where('id', $v['us_id'])->value('bank_name');
//            if ($v['tx_type'] == 0) {
//                $account = 'bank_account';
//            } elseif ($v['tx_type'] == 1) {
//                $account = 'we_account';
//            } elseif ($v['tx_type'] == 2) {
//                $account = 'ali_account';
//            }
//            $list[$k]['tx_account'] = model('User')->where('id', $v['us_id'])->value($account);
//        }
//        $this->assign(array(
//            'list' => $list,
//        ));
//        return $this->fetch();
//    }

    //   审批提现
    public function commissionapply()
    {
        if (input('get.keywords')) {
            $us_id = model("User")->where('us_nickname|us_tel', input('get.keywords'))->value('id');
            if (!$us_id) {
                $us_id = 0;
            }
            $this->map[] = ['us_id', '=', $us_id];
        }
        $this->map[] = ['type','=',2];
        $list = \model('PayInfo')->where($this->map)
            ->paginate(10,false,$config = ['query'=>request()->param()]);

        $money = model('PayInfo')->where($this->map)->sum('xf_money');

        foreach ($list as $k => $v) {
            if ($v['tixian_zh_type'] == 1) {
                $account = 'ali_account';
            } elseif ($v['tixian_zh_type'] == 2) {
                $account = 'we_account';
            }
            $list[$k]['tx_account'] = model('User')->where('id', $v['us_id'])->value($account);

            $userInfo = \model('user')->where('id',$v['us_id'])->find();
            $list[$k]['us_nickname']= $userInfo->us_nickname;
            $list[$k]['us_tel']= $userInfo->us_tel;
        }
//        halt($list);

        $this->assign(array('list' => $list, 'a' => $money));
        return $this->fetch();
    }


    //给予提现
    public function change()
    {
        if (is_post()) {
//            halt(input('post.id'));
            $data[input('post.key')] = input('post.value');
            $data['tixian_tg_time'] = date('Y-m-d H:i:s');

            $rst = model('payInfo')->save($data, ['id' => input('post.id')]);

            if ($rst) {
                return [
                    'code' => '1',
                    'msg' => '审批成功'
                ];
            }
            return [
                'code' => '0',
                'msg' => '审批失败'
            ];
        }
    }

    //驳回提现
    public function change2()
    {
        if (is_post()) {
            $tx_id = input('post.id'); //提现id
            $us_id = db('tixian')->where('id', $tx_id)->value('us_id');

            $data[input('post.key')] = input('post.value');
            $data['tx_back_time'] = date('Y-m-d H:i:s');
            model('Tixian')->saveInfo($data, ['id' => input('post.id')]);
            $info = model('Tixian')->where('id', input('post.id'))->find();
            $rst = model('User')->where('id', $info['us_id'])->setInc('us_all_get', $info['tx_num']);
            $over_money = db('user')->where('id', $us_id)->value('us_all_get');
            db('pay_info')
                ->where('us_id', $us_id)
                ->where('tixian_type', 0)
                ->update(['tixian_type' => 2, 'over_money' => $over_money]);

            if ($rst) {
                return [
                    'code' => '1',
                    'msg' => '驳回成功'
                ];
            }
            return [
                'code' => '0',
                'msg' => '驳回失败'
            ];
        }
    }





    //通过运营中心申请
    public function changezx()
    {
        if (is_post()) {
            $data[input('post.key')] = input('post.value');
            $data['tx_add_time'] = date('Y-m-d H:i:s');
            model('Tixian')->saveInfo($data, ['id' => input('post.id')]);
            $user_id = db('tixian')->where('id', input('post.id'))->value('us_id');
//            $type = [ 'us_type'=> 3];
            $user = db('user')->where('id', $user_id)->find();
            //给推荐人发放奖金
            $level = $user['us_type'];        //用户类型
            $u_id = $user['id'];   //用户id
            $or_id = 0;
            $user_type = model('user')->where('id', $user['id'])->value('us_type');
            $t_user_id = $user['us_pid'];   //  推荐人id
            $t_user_type = model('user')->where('id', $t_user_id)->value('us_type');  //推荐人角色类型

            //未激活会员审核通过
            if ($level == 0) {
                $change_level['us_type'] = 3; //更改用户类型
                $rel = model('user')->where('id', $user['id'])->update($change_level);
                if ($rel) {
                    $bonus = new WalletLogic();
                    // @param $referrer_type   推荐人角色类型         $t_user_type
                    //@param $user_type        推荐人推荐角色的类型     $user_type
                    //@param $us_id            推荐人id (给其发奖金)    $t_user_id
                    // @param $s_id            推荐用户生成的id        $u_id
                    return $bonus->index($t_user_type, $user_type, $t_user_id, $u_id, $or_id);
                } else {
                    return ['code' => '0', 'msg' => '升级失败'];
                    //$this->e_msg('用户等级升级失败');
                }
                //在这调用钱包逻辑里的方法
            }
            //会员审核通过
            if ($level == 1) {
                $change_level['us_type'] = 3; //更改用户类型
                $rel = model('user')->where('id', $user['id'])->update($change_level);
                $user_type = model('user')->where('id', $user['id'])->value('us_type');
                if ($rel) {
                    $bonus = new WalletLogic();
                    // @param $referrer_type   推荐人角色类型         $t_user_type
                    //@param $user_type        推荐人推荐角色的类型     $user_type
                    //@param $us_id            推荐人id (给其发奖金)    $t_user_id
                    // @param $s_id            推荐用户生成的id        $u_id
                    return $bonus->index($t_user_type, $user_type, $t_user_id, $u_id, $or_id);
                } else {
                    return ['code' => '0', 'msg' => '升级失败'];
                    //$this->e_msg('用户等级升级失败');
                }
                //在这调用钱包逻辑里的方法
            }
            //店主审核通过
            if ($level == 2) {
                $change_level['us_type'] = 3; //更改用户类型
                $rel = model('user')->where('id', $user['id'])->update($change_level);
                $user_type = model('user')->where('id', $user['id'])->value('us_type');
                if ($rel) {
                    $bonus = new WalletLogic();
                    // @param $referrer_type   推荐人角色类型         $t_user_type
                    //@param $user_type        推荐人推荐角色的类型     $user_type
                    //@param $us_id            推荐人id (给其发奖金)    $t_user_id
                    // @param $s_id            推荐用户生成的id        $u_id
                    return $bonus->index($t_user_type, $user_type, $t_user_id, $u_id, $or_id);
                } else {
                    return ['code' => '0', 'msg' => '升级失败'];
                    //$this->e_msg('用户等级升级失败');
                }
                //在这调用钱包逻辑里的方法
            }


//            if($ret){
//                return [
//                    'code' => '1',
//                    'msg' => '该用户已成为运营中心'
//                ];
//            }
//            return [
//                'code' => '0',
//                'msg' => '升级失败'
//            ];
        }
    }

    //驳回运营中心申请
    public function changezx2()
    {
        if (is_post()) {

            $data[input('post.key')] = input('post.value');
            $data['tx_back_time'] = date('Y-m-d H:i:s');
            model('Tixian')->saveInfo($data, ['id' => input('post.id')]);
            $info = model('Tixian')->where('id', input('post.id'))->find();
            $rst = model('User')->where('id', $info['us_id'])->setInc('us_all_get', $info['tx_num']);
            if ($rst) {
                return [
                    'code' => '1',
                    'msg' => '驳回成功'
                ];
            }
            return [
                'code' => '0',
                'msg' => '驳回失败'
            ];
        }
    }



    // 微信支付记录
    public function wechat()
    {
        if (is_post()) {

            $rst = model('Order')->xiugai([input('post.key') => input('post.value')], ['id' => input('post.id')]);
            return $rst;
        }
        if (input('get.keywords')) {
            $us_id = model("User")->where('us_account|us_real_name|us_tel', input('get.keywords'))->value('id');
            if (!$us_id) {
                $us_id = 0;
            }
            $this->map[] = ['us_id', '=', $us_id];
        }
        if (input('get.wa_type') != "") {
            $this->map[] = ['wa_type', '=', input('get.wa_type')];
        }
        $list = model('PayWechat')->chaxun($this->map, $this->order, $this->size);

        $this->assign(array(
            'list' => $list,
        ));
        return $this->fetch();
    }

    public function paylist()
    {
        if (input('get.keywords')) {
            $us_id = model("User")->where('us_nickname|us_tel', input('get.keywords'))->value('id');
            if (!$us_id) {
                $us_id = 0;
            }
            $this->map[] = ['us_id', '=', $us_id];
        }
        $field = 'a.* , b.us_nickname , b.us_tel , b.us_account';
        $paymodel = model('PayWechat');
        $list = $paymodel->chaxun($this->map, $this->order, $this->size, $field);
        $todaysold = $paymodel->where('status', 1)->whereTime('add_time', 'today')->sum('money');
        $allsold = $paymodel->where('status', 1)->sum('money');
        $this->assign(array(
            'list' => $list,
            'todaysold' => $todaysold,
            'allsold' => $allsold,
        ));
        return $this->fetch();
    }




    /**
     * 交易明细
     */
    public function birecord()
    {
        if (input('get.keywords')) {
            $this->map[] = ['us_id', '=', input('get.keywords')];
        }
        if (input('get.start') && input('get.end') == "") {
            $this->map[] = ['add_time', '>=', input('get.start')];
        }
        if (input('get.start') == "" && input('get.end')) {
            $this->map[] = ['add_time', '<=', input('get.end')];
        }
        if (input('get.start') && input('get.end')) {
            $this->map[] = ['add_time', 'between', array(input('get.start'), input('get.end'))];
        }
//        if (input('get.wa_type')) {
//            $this->map[] = ['wa_type', '=', input('get.wa_type')];
//        }
//        $list = model('wallet')->getList($this->map, $this->order, $this->size, '');
        $list = model('PayInfo')
            ->where($this->map)
            ->order('add_time', 'desc')
            ->paginate(10, false, $config = ['query' => request()->param()]);

        foreach ($list as $k => $v) {
            $list[$k]['us_nickname'] = db('user')->where('id', $v['us_id'])->value('us_nickname');
            $or_id = db('order')->where('or_num', $v['or_num'])->value('id');
            $list[$k]['shangping_name'] = db('order_detail')->where('or_id', $or_id)->value('or_pd_name');
        }
        $money = model('PayInfo')->where($this->map)
            ->order('add_time', 'desc')
            ->sum('xf_money');


        $this->assign(['list' => $list, 'money' => $money]);
        return $this->fetch();
    }






    /**
     * 收益记录明细
     */
    public function gainDetail()
    {
        if (input('get.us_name')) {
            $this->map[] = ['us_id','=',input('get.us_name')];
        }

        if (input('get.order_num')) {
            $this->map[] = ['or_num', '=',input('get.order_num')];
        }

        if (input('get.start') && input('get.end') == "") {
            $this->map[] = ['add_time', '>=', input('get.start')];
        }
        if (input('get.start') == "" && input('get.end')) {
            $this->map[] = ['add_time', '<=', input('get.end')];
        }
        if (input('get.start') && input('get.end')) {
            $this->map[] = ['add_time', 'between', array(input('get.start'), input('get.end'))];
        }

        $list = model('PayInfo')
            ->where($this->map)
            ->where(['type'=>[3,5]])
            ->order('add_time', 'desc')
            ->paginate(10, false, $config = ['query' => request()->param()]);

//        halt($list);
        foreach ($list as $k=>$v)
        {
            $list[$k]['us_nickname']= \model('user')->where('id',$v['us_id'])->value('us_nickname');
            $list[$k]['order_num']=\model('order')->where('id',$v['or_num'])->value('or_num');
            $list[$k]['tuijian_nickname']= \model('user')->where('id',$v['tuijian_id'])->value('us_nickname');
            $or_status = \model('order')->where('or_num',$v['or_num'])->value('or_status');

            if ($or_status == 3){
             \model('PayInfo')->where('or_num',$v['or_num'])->update(['type_account' =>1]);
             $list[$k]['type_account'] = 1;
            }else{
                model('PayInfo')->where('or_num',$v['or_num'])->update(['type_account' =>2]);
                $list[$k]['type_account'] = 2;
            }
        }
//        halt($list);

        $money =  model('PayInfo')
            ->where('type',3)
            ->where($this->map)
            ->order('add_time', 'desc')
            ->sum('xf_money');
        $this->assign(['list' => $list,'money'=>$money]);

        return $this->fetch();

    }

    public function shouzhi()
    {
        if (input('get.type')) {
            $this->map[] = ['type', '=', input('get.type')];
        }
        if (input('get.pay_type')) {
            $this->map[] = ['pay_type', '=', input('get.pay_type')];
        }
        if (input('get.start') && input('get.end') == "") {
            $this->map[] = ['add_time', '>=', input('get.start')];
        }
        if (input('get.start') == "" && input('get.end')) {
            $this->map[] = ['add_time', '<=', input('get.end')];
        }
        if (input('get.start') && input('get.end')) {
            $this->map[] = ['add_time', 'between', array(input('get.start'), input('get.end'))];
        }
        $list = model('PayInfo')->where($this->map)
            ->order('add_time', 'desc')
            ->paginate(10, false, $config = ['query' => request()->param()]);
        foreach ($list as $k => $v) {
            $list[$k]['us_nickname'] = db('user')->where('id', $v['us_id'])->value('us_nickname');
            $or_id = db('order')->where('or_num', $v['or_num'])->value('id');
            $list[$k]['shangping_name'] = db('order_detail')->where('or_id', $or_id)->value('or_pd_name');
        }
        $money = model('PayInfo')->where($this->map)
            ->order('add_time', 'desc')
            ->sum('xf_money');

        $this->assign(['list' => $list, 'money' => $money]);
        return $this->fetch();
    }


    /**
     * 取消奖励
     * @return array
     * @throws \think\Exception
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function cancelbi()
    {
        $id = input('post.id');
        $wa_model = model('Wallet');
        $u_model = model('User');
        $wa_info = $wa_model->where('id', $id)->find();
        $us_id = $wa_info['us_id'];
        $rel1 = $u_model->where('id', $us_id)->setDec('us_shop_bi', $wa_info['get_bi']);
        $rel2 = $u_model->where('id', $us_id)->setDec('us_all_get', $wa_info['wa_num']);
        $rel3 = $wa_model->where('id', $id)->delete();
        return ['code' => 1, 'msg' => '取消成功'];
    }

    public function excel(){//导出Excel

//        halt(input('get.'));
        $start = input('get.time_start');
        $end = input('get.time_send');
        $start_time = date("Y-m-d H:i:s",$start/1000);
        $end_time =$end!='NaN'? date("Y-m-d H:i:s",$end/1000):date('Y-m-d H:i:s');

        if ($start && $start == "") {
            $this->map[] = ['add_time', '>=', $start_time];
        }
        if ($start == "" && $end) {
            $this->map[] = ['add_time', '<=', $end_time];
        }
        if ($start && $end) {
            $this->map[] = ['add_time', 'between', array($start_time, $end_time)];
        }

//        $info = Db::name('pay_info')
//            ->where($this->map)
//            ->select();


        $info = db('pay_info')
            ->where($this->map)
            ->order('add_time', 'desc')
            ->select();

        foreach ($info as $k=>$v)
        {
            $info[$k]['us_nickname']= db('user')->where('id',$v['us_id'])->value('us_nickname');
            $info[$k]['order_num']=db('order')->where('id',$v['or_num'])->value('or_num');
            $info[$k]['us_tel']= db('user')->where('id',$v['us_id'])->value('us_tel');
            $info[$k]['tuijian_nickname']= db('user')->where('id',$v['tuijian_id'])->value('us_nickname');
            $or_id = db('order')->where('or_num', $v['or_num'])->value('id');
            $info[$k]['shangping_name'] = db('order_detail')->where('or_id', $or_id)->value('or_pd_name');
        }
        $xlsName  = "交易明细";
        $xlsCell  = array(
            array('us_id', '用户ID'),
            array('us_nickname', '用户昵称'),
            array('us_tel', '用户手机号'),
            array('y_money', '原金额'),
            array('xf_money', '交易金额'),
            array('or_num', '订单号'),
            array('over_money', '余额'),
            array('tuijian_shouyi_type', '说明'),
            array('type', '类型'),

        );

        $xlsData  = array();
        // halt($info['list']);
//        unset($info['list']['total']);
        foreach ($info as $k => $v) {
            if ($v['type'] == 1) {
                $xlsData[$k]['type'] = '消费';
            } elseif ($v['type'] == 2) {
                $xlsData[$k]['type'] = '提现';
            } elseif ($v['type'] == 3) {
                $xlsData[$k]['type'] = '推荐收益';
            }elseif ($v['type'] == 4) {
                $xlsData[$k]['type'] = '后台添加';
            } else{
                $xlsData[$k]['type'] = '';
            }

            $xlsData[$k]['us_id'] = $v['us_id'];
            $xlsData[$k]['us_nickname'] = $v['us_nickname'];
            $xlsData[$k]['us_tel'] = $v['us_tel'];
            $xlsData[$k]['y_money'] = $v['y_money'];
            $xlsData[$k]['xf_money'] = $v['xf_money'];
            $xlsData[$k]['or_num'] = $v['or_num'];
            $xlsData[$k]['over_money'] = $v['over_money'];
            if ($v['type'] == 1) {
                $xlsData[$k]['tuijian_shouyi_type'] = '商品名：'.$v['shangping_name'];
            } elseif ($v['type'] == 2) {
                $xlsData[$k]['tuijian_shouyi_type'] = '提现';
            } elseif ($v['type'] == 3) {
                $xlsData[$k]['tuijian_shouyi_type'] =$v['tuijian_shouyi_type'];
            }else{
                $xlsData[$k]['tuijian_shouyi_type'] ='';
            }
        }
        $this->exportExcel($xlsName,$xlsCell,$xlsData);
    }

    public function szExcel(){//导出Excel

        $type = input('get.type');
        $pay_type = input('get.pay_type');
        $start = input('get.time_start');
        $end = input('get.time_send');
        $start_time = date("Y-m-d H:i:s",$start/1000);
        $end_time =$end!='NaN'? date("Y-m-d H:i:s",$end/1000):date('Y-m-d H:i:s');

        if ($type){
            $this->map[] = ['type', '=', $type];
        }
        if ($pay_type){
            $this->map[] = ['pay_type', '=', $pay_type];
        }
        if ($start && $start == "") {
            $this->map[] = ['add_time', '>=', $start_time];
        }
        if ($start == "" && $end) {
            $this->map[] = ['add_time', '<=', $end_time];
        }
        if ($start && $end) {
            $this->map[] = ['add_time', 'between', array($start_time, $end_time)];
        }
        $info = db('pay_info')
            ->where($this->map)
            ->order('add_time', 'desc')
            ->select();
//        halt($info);
        foreach ($info as $k=>$v)
        {
            $info[$k]['us_nickname']= db('user')->where('id',$v['us_id'])->value('us_nickname');
            $info[$k]['order_num']=db('order')->where('id',$v['or_num'])->value('or_num');
            $info[$k]['us_tel']= db('user')->where('id',$v['us_id'])->value('us_tel');
            $info[$k]['tuijian_nickname']= db('user')->where('id',$v['tuijian_id'])->value('us_nickname');
            $or_id = db('order')->where('or_num', $v['or_num'])->value('id');
            $info[$k]['shangping_name'] = db('order_detail')->where('or_id', $or_id)->value('or_pd_name');
        }
        $xlsName  = "交易明细";
        $xlsCell  = array(
            array('us_id', '用户ID'),
            array('us_nickname', '用户昵称'),
            array('us_tel', '用户手机号'),
            array('y_money', '原金额'),
            array('xf_money', '交易金额'),
            array('or_num', '订单号'),
            array('over_money', '余额'),
            array('tuijian_shouyi_type', '说明'),
            array('type', '类型'),
            array('pay_type', '支付类型')
        );



        $xlsData  = array();
        // halt($info['list']);
//        unset($info['list']['total']);
        foreach ($info as $k => $v) {
            if ($v['type'] == 1) {
                $xlsData[$k]['type'] = '消费';
            } elseif ($v['type'] == 2) {
                $xlsData[$k]['type'] = '提现';
            } elseif ($v['type'] == 3) {
                $xlsData[$k]['type'] = '推荐收益';
            } elseif ($v['type'] == 4) {
                $xlsData[$k]['type'] = '后台充值';
            }else{
                $xlsData[$k]['type'] = '';
            }

            if ($v['pay_type'] == 1) {
                $xlsData[$k]['pay_type'] = '钱包';
            } elseif ($v['pay_type'] == 2) {
                $xlsData[$k]['pay_type'] = '微信';
            } elseif ($v['pay_type'] == 3) {
                $xlsData[$k]['pay_type'] = '支付宝';
            }else{
                $xlsData[$k]['pay_type'] = '';
            }

            $xlsData[$k]['us_id'] = $v['us_id'];
            $xlsData[$k]['us_nickname'] = $v['us_nickname'];
            $xlsData[$k]['us_tel'] = $v['us_tel'];
            $xlsData[$k]['y_money'] = $v['y_money'];
            $xlsData[$k]['xf_money'] = $v['xf_money'];
            $xlsData[$k]['or_num'] = $v['or_num'];
            $xlsData[$k]['over_money'] = $v['over_money'];


            if ($v['type'] == 1) {
                $xlsData[$k]['tuijian_shouyi_type'] = '商品名：'.$v['shangping_name'];
            } elseif ($v['type'] == 2) {
                $xlsData[$k]['tuijian_shouyi_type'] = '提现';
            } elseif ($v['type'] == 3) {
                $xlsData[$k]['tuijian_shouyi_type'] =$v['tuijian_shouyi_type'];
            }elseif ($v['type'] == 4) {
                $xlsData[$k]['tuijian_shouyi_type'] ='后台充值';
            }else{
                $xlsData[$k]['tuijian_shouyi_type'] ='';
            }
        }
//        halt($xlsData);
        $this->exportExcel($xlsName,$xlsCell,$xlsData);
    }

    function exportExcel($expTitle,$expCellName,$expTableData){
        //include_once EXTEND_PATH.'PHPExcel/PHPExcel.php';//方法二
        $xlsTitle = iconv('utf-8', 'gb2312', $expTitle);//文件名称
        $fileName = $expTitle.date('_YmdHis');//or $xlsTitle 文件名称可根据自己情况设定
        $cellNum = count($expCellName);
        $dataNum = count($expTableData);
        $num = $dataNum + 3;
        $objPHPExcel = new PHPExcel();//方法一
        //$objPHPExcel = new \PHPExcel();//方法二
        $cellName = array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','AA','AB','AC','AD','AE','AF','AG','AH','AI','AJ','AK','AL','AM','AN','AO','AP','AQ','AR','AS','AT','AU','AV','AW','AX','AY','AZ');
        $objPHPExcel->getActiveSheet(0)->mergeCells('A1:'.$cellName[$cellNum-1].'1');//合并单元格
        $objPHPExcel->getActiveSheet(0)->mergeCells('A'.$num.':'.$cellName[$cellNum-1].$num);//合并单元格
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('A1', $expTitle.'  表格生成时间:'.date('Y-m-d H:i:s'));
        // halt($num);
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('A'.$num, '制表人:                      ' . '会计：                      ' . '出纳：                      ' . '审核：                      ');
        for($i=0;$i<$cellNum;$i++){
            $objPHPExcel->setActiveSheetIndex(0)->setCellValue($cellName[$i].'2', $expCellName[$i][1]);
        }
        // Miscellaneous glyphs, UTF-8
        for($i=0;$i<$dataNum;$i++){
            for($j=0;$j<$cellNum;$j++){
                $objPHPExcel->getActiveSheet(0)->setCellValue($cellName[$j].($i+3), $expTableData[$i][$expCellName[$j][0]]);
            }
        }
        ob_end_clean();//这一步非常关键，用来清除缓冲区防止导出的excel乱码
        header('pragma:public');
        header('Content-type:application/vnd.ms-excel;charset=utf-8;name="'.$xlsTitle.'.xls"');
        header("Content-Disposition:attachment;filename=$fileName.xls");//"xls"参考下一条备注
        $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');//"Excel2007"生成2007版本的xlsx，"Excel5"生成2003版本的xls
        $objWriter->save('php://output');
        exit;
    }




}
